using Services;
using UnityEngine;

[RequireComponent(typeof(PointTrigger_Player))]
public class DialogTrigger : MonoBehaviour
{
    private GameManager gameManager;
    [SerializeField]
    protected DialogGraph dialogGraph;
    protected PointTrigger_Player trigger;
    protected DialogSystem dialogSystem;

    protected virtual void Awake()
    {
        dialogGraph.Initailize();
        gameManager = ServiceLocator.Get<GameManager>();
        trigger = GetComponent<PointTrigger_Player>();
        trigger.OnTriggerStay += MyOnTriggerStay;
        dialogSystem = GeneralTool.FindComponent<DialogSystem>("DialogUI");
    }

    protected virtual void MyOnTriggerStay(Player player)
    {
        if (Input.GetKeyDown(KeyCode.F) && gameManager.GameState != EGameState.Dialog)
        {
            dialogSystem.dialogGraph = dialogGraph;
            gameManager.GameState = EGameState.Dialog;
        }
    }
}
